package org.itv.nettysrv;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;

@SuppressWarnings("deprecation")
@ChannelPipelineCoverage("all")
public class DiscardServerHandler extends SimpleChannelHandler {
	public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
		ChannelBuffer buf = (ChannelBuffer) e.getMessage();
//		System.out.println("server buf:"+buf.getInt(0));
		
		while (buf.readable()) {
			System.out.println((char) buf.readByte());
		}
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
			throws Exception {
		// TODO Auto-generated method stub
		// super.exceptionCaught(ctx, e);

		e.getCause().printStackTrace();
		Channel ch = e.getChannel();
		ch.close();
	}

}
